package com.zhaopin.gitlab;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static java.time.temporal.ChronoField.MILLI_OF_DAY;

public class Test3 {

    public static void main(String[] args) throws IOException, InterruptedException {

        String str = "2022-08-16T03:13:43Z";
        String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
        String pattern1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
        System.out.println(isAfterNow(str, 15, pattern,pattern1));

//        System.out.println(localDateTime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli());

//        long beforeTimes = System.currentTimeMillis();
//        Thread.sleep(1000L);
//        long afterTimes = System.currentTimeMillis() - beforeTimes;
//        System.out.println("zml_rank_up_zmlscore elapsed: " + afterTimes + " ms");


//        double b = 0.29376372238896215D;
//        BigDecimal bigDistance = new BigDecimal(12748615);
//        BigDecimal bigDenominator = new BigDecimal(5000);
//        BigDecimal bigScore = new BigDecimal(b);
//
//
//        BigDecimal bigDecimal = new BigDecimal(Math.E);
//        System.out.println((12748615 / 5000));
//        System.out.println(bigDecimal.pow(5));
//
//        System.out.println("-----" + Math.pow(Math.E, 5));
//        System.out.println((Math.pow(Math.E, 12748615 / 5000) - 1));
//        System.out.println((1 / b));
//
//        System.out.println((Math.pow(Math.E, 12748615 / 5000) - 1) * (float)(1 / (float)b));


//        String s = FileUtils.readFileToString(new File("/Users/zhaopin/IdeaProjects/easyjar/dir/a.json"), Charset.defaultCharset());
//        JSONArray jsonArray = JSONArray.parseArray(s);
//        List<Object> collect = jsonArray.stream().sorted((a, b) -> {
//            JSONObject jsonObject1 = (JSONObject) a;
//            JSONObject jsonObject2 = (JSONObject) b;
//            if (jsonObject1.getDouble("reRankScore") > jsonObject2.getDouble("reRankScore")) {
//                return 1;
//            } else {
//                return -1;
//            }
//
//        }).collect(Collectors.toList());
//        System.out.println(collect);
//

//        String str = "24H|2";
//        String[] split = str.split("\\|");
//        System.out.println(split[0]);
//        System.out.println(split[1]);
//
//
//         List<String> list = new ArrayList<>();
//        Set<String> set = list.stream().collect(Collectors.toSet());

//        List<String> listJobType = new ArrayList<>();
//        listJobType.add("1111");
//        listJobType.add("1112");
//        listJobType.add("1111");
//        listJobType.add("1113");
//        List<String> listMerged = listJobType.stream().collect(
//                Collectors.collectingAndThen( Collectors.toCollection(() -> new HashSet<>()), ArrayList::new)
//        );
//
//        System.out.println(listMerged.subList(1,3));

//        JSONObject userJobType30d = JSON.parseObject("{   \"11001000040000\": 0.3168,   \"11001000080000\": 0.2562,   \"14000700060000\": 0.3722 }");
//        userJobType30d.forEach(
//                (t,v) -> {
//                    System.out.println(t);
//
//                    System.out.println(v);
//                    System.out.println("--");
//                }
//        );

//        double a = 2.4;
//        double a1 = 2.49999999;
//        double a2 = 2.5000000001;
//        double b = 2.6;
//        System.out.println(Math.round(a));
//        System.out.println(Math.round(b));
//        System.out.println(Math.round(a1));
//        System.out.println(Math.round(a2));


//        List<String> list = new ArrayList<>();
//        list.add("a");
//        list.add("b");
//        list.add("c");
//        list.remove(1);
//        System.out.println(list);

    }

    public static boolean isAfterNow(long time, int days) {
        time = time + days * (24 * 3600 * 1000);
        long l2 = System.currentTimeMillis();
        return l2 - time > 0 ? true : false;
    }

    /**
     * 输入的String类型的时间距今长时间 是否超过days
     *
     * @param time
     * @param days
     * @param pattern
     * @return
     */
    public static boolean isAfterNow(String time,int days ,String pattern ,String pattern1){
        if(time != null){
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
            LocalDateTime from = LocalDateTime.now();
            try {
                from = LocalDateTime.parse(time, formatter);
            }catch(DateTimeParseException e){
                formatter = DateTimeFormatter.ofPattern(pattern1);
                from = LocalDateTime.parse(time, formatter);
            }
            LocalDateTime localDateTime = from.plusDays(days);
            return localDateTime.isAfter(LocalDateTime.now());

        }
        return false;

    }
}
